package pro.jiug.kExcel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import pro.jiug.kExcel.entity.User;
import pro.jiug.kExcel.mapper.UserMapper;
import pro.jiug.kExcel.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户操作
 *
 * @author Keffett
 * @since 2021-02-19
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> findSameNameUser(User user){
        Map<String,Object> queryParam=new HashMap<>();
        queryParam.put("name",user.getName());
        List<User> users = userMapper.selectByMap(queryParam);

        //分页条件
        Page<User> pageInfo=new Page<>();
        //查询条件
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(user.getName())){
            queryWrapper.like("name",user.getName());
        }
        //查询结果
        Page<User> page = userMapper.selectPage(pageInfo, queryWrapper);

        return users;
    }

    @Override
    public PageInfo<User> findPage(Integer pageNum, Integer pageSize, User user){
        //查询条件
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(user.getName())){
            queryWrapper.like("name",user.getName());
        }

        //分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userMapper.llp();//查询结果
//        List<User> users = userMapper.selectList(queryWrapper);//查询结果
        PageInfo<User> page = new PageInfo<>(users);

        return page;
    }

}
